package labox.innovation.gameserver.skills.conditions;

import labox.innovation.gameserver.instancemanager.InstanceManager;
import labox.innovation.gameserver.instancemanager.InstanceManager.InstanceWorld;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.skills.Env;
import javolution.util.FastList;

public class ConditionPlayerInstanceId extends Condition {
	private final FastList<Integer> _instanceIds;

	public ConditionPlayerInstanceId(FastList<Integer> instanceIds) {
		_instanceIds = instanceIds;
	}

	@Override
	public boolean testImpl(Env env) {
		if (!(env.player instanceof FuzePcInstance))
			return false;

		final int instanceId = env.player.getInstanceId();
		if (instanceId <= 0)
			return false; // player not in instance

		final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld((FuzePcInstance) env.player);
		if (world == null || world.instanceId != instanceId)
			return false; // player in the different instance

		return _instanceIds.contains(world.templateId);
	}
}